<!DOCTYPE html><html lang="en" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>利用ChatGPT帮助理解fork()函数，通俗易懂 | Hexo</title><meta name="author" content="JoshuaLi"><meta name="copyright" content="JoshuaLi"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="利用ChatGPT帮助fork()函数，通俗易懂">
<meta property="og:type" content="article">
<meta property="og:title" content="利用ChatGPT帮助理解fork()函数，通俗易懂">
<meta property="og:url" content="http://joshua-li.gitee.io/joshuali/2023/06/14/%E5%88%A9%E7%94%A8ChatGPT%E5%B8%AE%E5%8A%A9fork()%E5%87%BD%E6%95%B0%EF%BC%8C%E9%80%9A%E4%BF%97%E6%98%93%E6%87%82/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="利用ChatGPT帮助fork()函数，通俗易懂">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png">
<meta property="article:published_time" content="2023-06-14T14:27:07.000Z">
<meta property="article:modified_time" content="2023-06-14T14:31:29.391Z">
<meta property="article:author" content="JoshuaLi">
<meta property="article:tag" content="操作系统">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png"><link rel="shortcut icon" href="/joshuali/img/favicon.png"><link rel="canonical" href="http://joshua-li.gitee.io/joshuali/2023/06/14/%E5%88%A9%E7%94%A8ChatGPT%E5%B8%AE%E5%8A%A9fork()%E5%87%BD%E6%95%B0%EF%BC%8C%E9%80%9A%E4%BF%97%E6%98%93%E6%87%82/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/joshuali/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/joshuali/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '利用ChatGPT帮助理解fork()函数，通俗易懂',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-06-14 22:31:29'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"><link rel="alternate" href="/joshuali/atom.xml" title="Hexo" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/joshuali/archives/"><div class="headline">Articles</div><div class="length-num">3</div></a><a href="/joshuali/tags/"><div class="headline">Tags</div><div class="length-num">2</div></a><a href="/joshuali/categories/"><div class="headline">Categories</div><div class="length-num">1</div></a></div><hr class="custom-hr"/></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header"><nav id="nav"><span id="blog-info"><a href="/joshuali/" title="Hexo"><span class="site-name">Hexo</span></a></span><div id="menus"><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">利用ChatGPT帮助理解fork()函数，通俗易懂</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2023-06-14T14:27:07.000Z" title="Created 2023-06-14 22:27:07">2023-06-14</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2023-06-14T14:31:29.391Z" title="Updated 2023-06-14 22:31:29">2023-06-14</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/joshuali/categories/%E7%AC%94%E8%AE%B0/">笔记</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="利用ChatGPT帮助理解fork()函数，通俗易懂"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post View:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="利用ChatGPT帮助理解fork-函数，通俗易懂"><a href="#利用ChatGPT帮助理解fork-函数，通俗易懂" class="headerlink" title="利用ChatGPT帮助理解fork()函数，通俗易懂"></a>利用ChatGPT帮助理解fork()函数，通俗易懂</h1><h5 id="问："><a href="#问：" class="headerlink" title="问："></a>问：</h5><blockquote>
<p>能不能用生活例子来解释一下fork()函数</p>
</blockquote>
<h5 id="ChatGPT："><a href="#ChatGPT：" class="headerlink" title="ChatGPT："></a>ChatGPT：</h5><blockquote>
<p>当我们思考fork()时，可以将其比喻为一个家庭中的父母与子女的情景。</p>
<p>想象一对夫妇（父进程）有了一个孩子（子进程）。当他们决定要孩子时，他们会复制自己的基因和特征，从而创建了一个新的个体。</p>
<p>在生活中，当夫妇决定要孩子时，他们会发起一个”fork”操作。这个操作会将夫妇的特征和基因复制到新的个体中，就像操作系统将父进程的代码、数据和资源复制到子进程中一样。</p>
<p>当这个”fork”操作完成后，家庭中就有了两个几乎一模一样的个体：父母和孩子。在这个时刻之后，父母和孩子是独立的个体，他们可以同时进行不同的活动，彼此之间没有直接的依赖关系。</p>
<p>类似地，在程序中调用fork()函数时，父进程会复制自己的执行环境，创建了一个子进程。这两个进程在之后的执行过程中是独立的，它们可以同时执行不同的任务，彼此之间没有直接的影响。</p>
<p>通过这个家庭的例子，希望能更好地理解fork()函数的概念和行为。</p>
</blockquote>
<p>ChatGPT的这个解释应该是通俗易懂了，当前这个人决定要孩子时，相当于当前进程想要创建一个子进程，他可以在当前进程会发起一个”fork”操作（便生出了孩子）。在现实生活中，我们可以用年龄来区分父母和孩子，而在操作系统中，依靠fork()函数的返回值来区分父进程和子进程。<br>当执行代码 int res &#x3D; fork();<br>在fork()函数之后，父进程和子进程是并行执行的，各干各的事，除了res的值，其他内容完全相同，在父进程中，res的值是一个大于0的数，在子进程中，res的值等于0。（res&lt;0表示进程创建失败——流产了）因此，我们就可以根据res的值来区分父进程和子进程。区分了父进程和子进程后，就可以分别在不同的进程中执行相应的内容，当然也可以执行fork操作（生自己的孩子）。</p>
<h5 id="下面有一个例子可以结合理解"><a href="#下面有一个例子可以结合理解" class="headerlink" title="下面有一个例子可以结合理解"></a>下面有一个例子可以结合理解</h5><blockquote>
<p>编写一个进程创建实验程序fork.c，创建如图所示的进程族亲结构，其中p1是程序启动时由加载程序创建第一个进程。各进程的输出信息分别如下：<br>    p1：I am father process 	<br>p11: 当前时间是&lt; 年 月 日 时 分 秒&gt; 	<br>p12: I am young brother process 	<br>p121：我的学号是&lt;您的学号xxx&gt; 	<br>p122：我的姓名是&lt;您的姓名xxx&gt;<br>如图所示：</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">   p1</span><br><span class="line">   /\</span><br><span class="line">p11   p12</span><br><span class="line">        / \</span><br><span class="line">    p121   p122</span><br></pre></td></tr></table></figure>

<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;stdlib.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;unistd.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;sys/types.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;sys/wait.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;time.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">print_time</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">time_t</span> current_time;</span><br><span class="line">    time(&amp;current_time);</span><br><span class="line">    <span class="type">char</span>* time_str = ctime(&amp;current_time);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;当前时间是%s&quot;</span>, time_str);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">p121_process</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;p121：我的学号是&lt;您的学号xxx&gt;\n&quot;</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">p122_process</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;p122：我的姓名是&lt;您的姓名xxx&gt;\n&quot;</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">p12_process</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;p12: I am young brother process\n&quot;</span>);</span><br><span class="line">    <span class="type">pid_t</span> p121 = fork();</span><br><span class="line">    <span class="keyword">if</span> (p121 &lt; <span class="number">0</span>) &#123;</span><br><span class="line">        <span class="built_in">fprintf</span>(<span class="built_in">stderr</span>, <span class="string">&quot;Fork failed\n&quot;</span>);</span><br><span class="line">        <span class="built_in">exit</span>(<span class="number">1</span>);</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (p121 == <span class="number">0</span>) &#123;</span><br><span class="line">        <span class="comment">// Child process (p121)</span></span><br><span class="line">        p121_process();</span><br><span class="line">        <span class="built_in">exit</span>(<span class="number">0</span>);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="comment">// Parent process (p12)</span></span><br><span class="line">        <span class="type">pid_t</span> p122 = fork();</span><br><span class="line">        <span class="keyword">if</span> (p122 &lt; <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="built_in">fprintf</span>(<span class="built_in">stderr</span>, <span class="string">&quot;Fork failed\n&quot;</span>);</span><br><span class="line">            <span class="built_in">exit</span>(<span class="number">1</span>);</span><br><span class="line">        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (p122 == <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="comment">// Child process (p122)</span></span><br><span class="line">            p122_process();</span><br><span class="line">            <span class="built_in">exit</span>(<span class="number">0</span>);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="comment">// Parent process (p12)</span></span><br><span class="line">            wait(<span class="literal">NULL</span>); <span class="comment">// Wait for p122 to complete</span></span><br><span class="line">            wait(<span class="literal">NULL</span>); <span class="comment">// Wait for p121 to complete</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">p11_process</span><span class="params">()</span> &#123;</span><br><span class="line">    print_time();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">p1_process</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;p1: I am father process\n&quot;</span>);</span><br><span class="line">    <span class="type">pid_t</span> p11 = fork();</span><br><span class="line">    <span class="keyword">if</span> (p11 &lt; <span class="number">0</span>) &#123;</span><br><span class="line">        <span class="built_in">fprintf</span>(<span class="built_in">stderr</span>, <span class="string">&quot;Fork failed\n&quot;</span>);</span><br><span class="line">        <span class="built_in">exit</span>(<span class="number">1</span>);</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (p11 == <span class="number">0</span>) &#123;</span><br><span class="line">        <span class="comment">// Child process (p11)</span></span><br><span class="line">        p11_process();</span><br><span class="line">        <span class="built_in">exit</span>(<span class="number">0</span>);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="comment">// Parent process (p1)</span></span><br><span class="line">        <span class="type">pid_t</span> p12 = fork();</span><br><span class="line">        <span class="keyword">if</span> (p12 &lt; <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="built_in">fprintf</span>(<span class="built_in">stderr</span>, <span class="string">&quot;Fork failed\n&quot;</span>);</span><br><span class="line">            <span class="built_in">exit</span>(<span class="number">1</span>);</span><br><span class="line">        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (p12 == <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="comment">// Child process (p12)</span></span><br><span class="line">            p12_process();</span><br><span class="line">            <span class="built_in">exit</span>(<span class="number">0</span>);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="comment">// Parent process (p1)</span></span><br><span class="line">            wait(<span class="literal">NULL</span>); <span class="comment">// Wait for p12 to complete</span></span><br><span class="line">            wait(<span class="literal">NULL</span>); <span class="comment">// Wait for p11 to complete</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span> &#123;</span><br><span class="line">    p1_process();</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">Author: </span><span class="post-copyright-info"><a href="http://joshua-li.gitee.io/joshuali">JoshuaLi</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">Link: </span><span class="post-copyright-info"><a href="http://joshua-li.gitee.io/joshuali/2023/06/14/%E5%88%A9%E7%94%A8ChatGPT%E5%B8%AE%E5%8A%A9fork()%E5%87%BD%E6%95%B0%EF%BC%8C%E9%80%9A%E4%BF%97%E6%98%93%E6%87%82/">http://joshua-li.gitee.io/joshuali/2023/06/14/%E5%88%A9%E7%94%A8ChatGPT%E5%B8%AE%E5%8A%A9fork()%E5%87%BD%E6%95%B0%EF%BC%8C%E9%80%9A%E4%BF%97%E6%98%93%E6%87%82/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/joshuali/tags/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/">操作系统</a></div><div class="post_share"><div class="social-share" data-image="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="next-post pull-full"><a href="/joshuali/2023/06/09/%E5%86%99%E7%AE%97%E6%B3%95%E9%A2%98%E7%94%A8%E5%88%B0%E7%9A%84%E4%B8%80%E4%BA%9B%E5%B8%B8%E8%A7%81%E7%9A%84%E6%8A%80%E5%B7%A7%E3%80%81%E9%81%87%E5%88%B0%E7%9A%84%E5%9D%91%E3%80%81%E6%A8%A1%E6%9D%BF/" title="写算法题用到的一些常见的技巧、遇到的坑、模板"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">Next Post</div><div class="next_info">写算法题用到的一些常见的技巧、遇到的坑、模板</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/joshuali/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">JoshuaLi</div><div class="author-info__description">菜鸟写博客捏</div></div><div class="card-info-data site-data is-center"><a href="/joshuali/archives/"><div class="headline">Articles</div><div class="length-num">3</div></a><a href="/joshuali/tags/"><div class="headline">Tags</div><div class="length-num">2</div></a><a href="/joshuali/categories/"><div class="headline">Categories</div><div class="length-num">1</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>Announcement</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Catalog</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%88%A9%E7%94%A8ChatGPT%E5%B8%AE%E5%8A%A9%E7%90%86%E8%A7%A3fork-%E5%87%BD%E6%95%B0%EF%BC%8C%E9%80%9A%E4%BF%97%E6%98%93%E6%87%82"><span class="toc-number">1.</span> <span class="toc-text">利用ChatGPT帮助理解fork()函数，通俗易懂</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E9%97%AE%EF%BC%9A"><span class="toc-number">1.0.0.0.1.</span> <span class="toc-text">问：</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#ChatGPT%EF%BC%9A"><span class="toc-number">1.0.0.0.2.</span> <span class="toc-text">ChatGPT：</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E4%B8%8B%E9%9D%A2%E6%9C%89%E4%B8%80%E4%B8%AA%E4%BE%8B%E5%AD%90%E5%8F%AF%E4%BB%A5%E7%BB%93%E5%90%88%E7%90%86%E8%A7%A3"><span class="toc-number">1.0.0.0.3.</span> <span class="toc-text">下面有一个例子可以结合理解</span></a></li></ol></li></ol></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>Recent Post</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/joshuali/2023/06/14/%E5%88%A9%E7%94%A8ChatGPT%E5%B8%AE%E5%8A%A9fork()%E5%87%BD%E6%95%B0%EF%BC%8C%E9%80%9A%E4%BF%97%E6%98%93%E6%87%82/" title="利用ChatGPT帮助理解fork()函数，通俗易懂">利用ChatGPT帮助理解fork()函数，通俗易懂</a><time datetime="2023-06-14T14:27:07.000Z" title="Created 2023-06-14 22:27:07">2023-06-14</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/joshuali/2023/06/09/%E5%86%99%E7%AE%97%E6%B3%95%E9%A2%98%E7%94%A8%E5%88%B0%E7%9A%84%E4%B8%80%E4%BA%9B%E5%B8%B8%E8%A7%81%E7%9A%84%E6%8A%80%E5%B7%A7%E3%80%81%E9%81%87%E5%88%B0%E7%9A%84%E5%9D%91%E3%80%81%E6%A8%A1%E6%9D%BF/" title="写算法题用到的一些常见的技巧、遇到的坑、模板">写算法题用到的一些常见的技巧、遇到的坑、模板</a><time datetime="2023-06-09T13:46:07.000Z" title="Created 2023-06-09 21:46:07">2023-06-09</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/joshuali/2023/06/06/hello-world/" title="Hello World">Hello World</a><time datetime="2023-06-06T15:42:09.274Z" title="Created 2023-06-06 23:42:09">2023-06-06</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By JoshuaLi</div><div class="framework-info"><span>Framework </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>Theme </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="Switch Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="Back To Top"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/joshuali/js/utils.js"></script><script src="/joshuali/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>